package nsoft.swing.demo;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JPanel;

import nsoft.swing.container.NInputFieldPanel;

public class TextFieldDemo extends JPanel implements ActionListener {

	/**
	 *
	 */
	private static final long serialVersionUID = 1L;
	private DemoBean bean;

	public TextFieldDemo() {
		bean = new DemoBean();

		NInputFieldPanel inputFieldPanel = new NInputFieldPanel();
		inputFieldPanel.addField(bean, "name", "Name :", 0, 0);
		inputFieldPanel.addField(bean, "empId", "Emp Id :", 1, 0);
		inputFieldPanel.addField(bean, "age", "Age :", 2, 0);
		inputFieldPanel.addField(bean, "address1", "Address Line 1 :", 3, 0);
		inputFieldPanel.addField(bean, "address2", "Address Line 2 :", 4, 0);
		inputFieldPanel.addField(bean, "basic", "Basic Sal :", 5, 0);

		JButton button = new JButton("Print data");
		button.addActionListener(this);
		inputFieldPanel.addComponent(button, 6, 1);
		this.add(inputFieldPanel);

		/*
		 * panel.setLayout(new GridBagLayout()); GridBagConstraints constraints =
		 * new GridBagConstraints(); constraints.anchor =
		 * GridBagConstraints.EAST; constraints.gridx=0; constraints.gridy = 0;
		 * panel.add(new JLabel("Name :"),constraints); constraints.gridy++;
		 * panel.add(new JLabel("Emp Id :"),constraints); constraints.gridy++;
		 * panel.add(new JLabel("Age :"),constraints); constraints.gridy++;
		 * panel.add(new JLabel("Address Line 1 :"),constraints);
		 * constraints.gridy++; panel.add(new JLabel("Address Line 2
		 * :"),constraints); constraints.gridy++; panel.add(new JLabel("Basic
		 * Sal :"),constraints);
		 *
		 * constraints.gridx=1; constraints.gridy = 0; constraints.anchor =
		 * GridBagConstraints.WEST; constraints.fill = GridBagConstraints.BOTH;
		 * constraints.weightx = 0.5; panel.add(new
		 * NTextField(bean,"name"),constraints); constraints.gridy++;
		 * panel.add(new NTextField(bean,"empId"),constraints);
		 * constraints.gridy++; panel.add(new
		 * NTextField(bean,"age"),constraints); constraints.gridy++;
		 * panel.add(new NTextField(bean,"address1"),constraints);
		 * constraints.gridy++; panel.add(new
		 * NTextField(bean,"address2"),constraints); constraints.gridy++;
		 * panel.add(new NTextField(bean,"basic"),constraints);
		 * constraints.gridy++; JButton button = new JButton("Print data");
		 * button.addActionListener(this); panel.add(button,constraints);
		 */

		// DisplayEngine.startEngine();
		// DisplayEngine.show(panel);
	}

	public void actionPerformed(ActionEvent e) {
		System.out.println("Name : " + bean.getName());
		System.out.println("Emp Id : " + bean.getEmpId());
		System.out.println("Age : " + bean.getAge());
		System.out.println("Address Line 1 : " + bean.getAddress1());
		System.out.println("Address Line 2 : " + bean.getAddress2());
		System.out.println("Basic Sal : " + bean.getBasic());

	}

}
